package com.zhentao.controller;

import com.zhentao.pojo.User;
import com.zhentao.pojo.dto.WeChatCodeDTO;
import com.zhentao.pojo.vo.UsersLoginVO;
import com.zhentao.result.Result;
import com.zhentao.service.UserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@Slf4j
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    /**
     * 小程序微信授权登录
     * @param code
     * @return
     */
    @PostMapping("/auth/wechat")
    public Result authWechat(@RequestBody WeChatCodeDTO code) {
        UsersLoginVO userLoginVO = userService.authWechat(code);
        return Result.success(userLoginVO);
    }

    /**
     * 更新用户信息
     * @param userUpdateInfo
     * @return
     */
    @PostMapping("/updateUserInfo")
    public Result updateUserInfo(@RequestBody User userUpdateInfo) {
        boolean updated = userService.updateById(userUpdateInfo);
        if (updated) {
            return Result.success("用户信息更新成功");
        } else {
            return Result.failed("用户信息更新失败");
        }
    }
}
